package com.un.ebs.contract.listener;

import com.un.ebs.contract.service.ContractService;
import com.un.ebs.workflow.event.WorkflowInstancePushEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Async
public class ContractWorkflowInstancePushListener implements ApplicationListener<WorkflowInstancePushEvent> {

    @Resource
    private ContractService contractService;

    @Override
    public void onApplicationEvent(WorkflowInstancePushEvent event) {
        if (!event.isClose()) {
            return;
        }
        if(!event.isPass()){
            return;
        }

        switch (event.getInventoryTypeEnum()) {
            case CONTRACT_SALE:
            case CONTRACT_PURCHASE:
            case CONTRACT_SERVICE:
            case CONTRACT_TRIAL_PRODUCTION:
            case CONTRACT_OEM:
            case CONTRACT_REPAIR:
                contractService.workflowPass(event.getNoteId(), event.getNoteId());
                break;

        }
    }
}
